package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.Ztree;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTrainStudent;
import com.ruoyi.system.service.ISysTrainStudentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实训学员Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@Controller
@RequestMapping("/system/train_student")
public class SysTrainStudentController extends BaseController
{
    private String prefix = "system/train_student";

    @Autowired
    private ISysTrainStudentService sysTrainStudentService;

    @RequiresPermissions("system:train_student:view")
    @GetMapping()
    public String train_student()
    {
        return prefix + "/train_student";
    }

    /**
     * 查询实训学员列表
     */
    @RequiresPermissions("system:train_student:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysTrainStudent sysTrainStudent)
    {
        startPage();
        List<SysTrainStudent> list = sysTrainStudentService.selectSysTrainStudentList(sysTrainStudent);
        return getDataTable(list);
    }
    /**
     * 加载部门列表树
     */
    @GetMapping("/trainStudentTreeData")
    @ResponseBody
    public List<Ztree> trainStudentTreeData()
    {
        List<Ztree> ztrees = sysTrainStudentService.selectTrainStudentTree(new SysTrainStudent());
        return ztrees;
    }

    /**
     * 导出实训学员列表
     */
    @RequiresPermissions("system:train_student:export")
    @Log(title = "实训学员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysTrainStudent sysTrainStudent)
    {
        List<SysTrainStudent> list = sysTrainStudentService.selectSysTrainStudentList(sysTrainStudent);
        ExcelUtil<SysTrainStudent> util = new ExcelUtil<SysTrainStudent>(SysTrainStudent.class);
        return util.exportExcel(list, "实训学员数据");
    }

    /**
     * 新增实训学员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存实训学员
     */
    @RequiresPermissions("system:train_student:add")
    @Log(title = "实训学员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysTrainStudent sysTrainStudent)
    {
        return toAjax(sysTrainStudentService.insertSysTrainStudent(sysTrainStudent));
    }

    /**
     * 修改实训学员
     */
    @RequiresPermissions("system:train_student:edit")
    @GetMapping("/edit/{studentId}")
    public String edit(@PathVariable("studentId") Long studentId, ModelMap mmap)
    {
        SysTrainStudent sysTrainStudent = sysTrainStudentService.selectSysTrainStudentByStudentId(studentId);
        mmap.put("sysTrainStudent", sysTrainStudent);
        return prefix + "/edit";
    }

    /**
     * 修改保存实训学员
     */
    @RequiresPermissions("system:train_student:edit")
    @Log(title = "实训学员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysTrainStudent sysTrainStudent)
    {
        return toAjax(sysTrainStudentService.updateSysTrainStudent(sysTrainStudent));
    }

    /**
     * 删除实训学员
     */
    @RequiresPermissions("system:train_student:remove")
    @Log(title = "实训学员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysTrainStudentService.deleteSysTrainStudentByStudentIds(ids));
    }
}
